package com.kele;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @ClassName : listSum
 * @Author : kele
 * @Date: 2022/10/26 22:59
 * @Description :
 */

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class listSum {


    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {

        int add = 0;

        ArrayList<ListNode> list = new ArrayList<>();

        while (true) {
            ListNode sum = new ListNode();

            sum.val = l1.val + l2.val + add;
            if (sum.val < 9) {
                add = 0;
            } else {
                add = 1;
            }

            list.add(sum);

            if (l1.next == null && l2.next == null) {
                break;
            }

            if (l1.next != null) {
                l1 = l1.next;
            }
            if (l2.next != null) {
                l2 = l2.next;
            }
        }
//        list[0];
        return l1;
    }

    public static void main(String[] args) {

//        addTwoNumbers();
    }

}
